<template>
  <!-- 我拉黑的账号 黑号管理 -->
  <el-dialog title="黑号管理" :visible.sync="dialogVisible" :close-on-click-modal="false" width="1200px" append-to-body>
    <div v-loading="loading">
      <el-form class="search-form-new" :model="queryParams" ref="queryForm" :inline="true">
        <div class="search-box">
          <el-form-item label="游戏账号" prop="account">
            <el-input v-model="queryParams.account" placeholder="请输入游戏账号" clearable />
          </el-form-item>

          <!-- <el-form-item label="时间" prop="">
          <el-date-picker style="width: 300px" v-model="timer" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"  >
          </el-date-picker>
        </el-form-item> -->

          <el-form-item class="btns">
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置/刷新</el-button>
          </el-form-item>
        </div>
      </el-form>
      <div class="table_box">
        <el-table :data="tableData.records" stripe border>
          <el-table-column label="游戏帐号" align="center" prop="account" />
          <el-table-column label="游戏名称" align="center" prop="gameName" />
          <el-table-column label="录入时间" align="center" prop="createTime"></el-table-column>
          <el-table-column label="备注" align="center" prop="remark" />
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button type="text" style="color: red" @click="delItem(scope.row)">拉出黑名单</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="tableData.total > 0" :total="tableData.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

      </div>
    </div>
  </el-dialog>

</template>
<script>
import { myAddList, delBlackNew } from "@/api/black/black";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      timer: [],
      tableData: {
        records: [],
        total: 0,
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
    };
  },
  created() {},
  methods: {
    open() {
      this.dialogVisible = true;
      this.loading = false;
      this.tableData.records = [];
      this.tableData.total = 0;
      this.getList();
    },
    // 获取列表
    getList() {
      // queryParams 请求列表
      this.loading = true;
      if (this.timer && this.timer.length == 2) {
        this.queryParams.createTimeStart = this.timer[0] + " 00:00:00";
        this.queryParams.createTimeEnd = this.timer[1] + " 23:59:59";
      } else {
        this.queryParams.createTimeStart = "";
        this.queryParams.createTimeEnd = "";
      }

      this.loading = true;
      myAddList(this.queryParams)
        .then((res) => {
          this.loading = false;
          this.tableData.records = res.rows;
          this.tableData.total = res.total;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 删除记录
    delItem(row) {
      this.$confirm(
        `此操作会将账号 ${row.account} 从黑名单中删除, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          delBlackNew(row.id).then((res) => {
            this.$message({
              type: "success",
              message: "拉出黑名单成功!",
            });
            this.getList();
          });
        })
        .catch(() => {});
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timer = [];
      this.handleQuery();
    },
    resetQuery() {
      this.timer = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 20,
        createTimeStart: "",
        createTimeEnd: "",
      };
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
